﻿<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
                   namespace="Projecturo.Model" 
                   assembly="Projecturo.Model"
                   default-lazy="false">

  <class name="User" table="[User]">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>

    <property name="FirstName" type="String"/>
    <property name="LastName" type="String"/>
    <property name="ShortName" type="String"/>
    <property name="Role" type="Int32"/>
    <property name="IsActive" type="Boolean"/>
    <property name="Username" type="String"/>
    <property name="Password" type="String"/>
    <property name="CreateDate" type="DateTime"/>
    <property name="ChangeDate" type="DateTime"/>

    <many-to-one name="DataContext" column="DataContextId" class="DataContext"/>
    <many-to-one name="CreatedBy" column="CreatedById" class="User"/>
    <many-to-one name="ChangedBy" column="ChangedById" class="User"/>
    
    <bag name="Projects" table="UserProject" lazy="false">
      <key column="UserId"/>
      <many-to-many class="Project" column="ProjectId"/>
    </bag>
  </class>
  
  <class name="DataContext" table="DataContext">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>

    <property name="Name" type="String"/>
  </class>

  <class name="Project" table="Project">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>

    <property name="Name" type="String"/>
    <property name="Description" type="String"/>
    <property name="CreateDate" type="DateTime"/>
    <property name="ChangeDate" type="DateTime"/>

    <many-to-one name="CreatedBy" column="CreatedById" class="User"/>
    <many-to-one name="ChangedBy" column="ChangedById" class="User"/>
    <many-to-one name="DefaultTicketState" column="DefaultTicketStateId" class="TicketState"/>
    <bag name="Tickets" table="Ticket" lazy="false" cascade="all">
      <key column="ProjectId"/>
      <one-to-many class="Ticket"/>
    </bag>

    <bag name="Milestones" table="Milestone" lazy="false" cascade="all">
      <key column="ProjectId"/>
      <one-to-many class="Milestone"/>
    </bag>
  </class>

  <class name="UserProject" table="UserProject">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>

    <many-to-one name="User" column="UserId" class="User"/>
    <many-to-one name="Project" column="ProjectId" class="Project"/>
    
  </class>

  <class name="Version" table="Version">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>

    <property name="Name" type="String"/>
    <property name="Description" type="String"/>
    <property name="CreateDate" type="DateTime"/>
    <property name="ChangeDate" type="DateTime"/>

    <many-to-one name="CreatedBy" column="CreatedById" class="User"/>
    <many-to-one name="ChangedBy" column="ChangedById" class="User"/>

    <many-to-one name="Project" column="ProjectId" class="Project"/>
    
  </class>

  <class name="Category" table="Category">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>

    <property name="Name" type="String"/>
    <property name="Description" type="String"/>
    <property name="CreateDate" type="DateTime"/>
    <property name="ChangeDate" type="DateTime"/>

    <many-to-one name="CreatedBy" column="CreatedById" class="User"/>
    <many-to-one name="ChangedBy" column="ChangedById" class="User"/>

    <many-to-one name="Project" column="ProjectId" class="Project"/>

  </class>

  <class name="TicketState" table="TicketState">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>

    <property name="Name" type="String"/>
    <property name="Color" type="String"/>
    <property name="IsActive" type="Boolean"/>
    <property name="CreateDate" type="DateTime"/>
    <property name="ChangeDate" type="DateTime"/>

    <many-to-one name="DataContext" column="DataContextId" class="DataContext"/>
    <many-to-one name="CreatedBy" column="CreatedById" class="User"/>
    <many-to-one name="ChangedBy" column="ChangedById" class="User"/>
    <many-to-one name="Project" column="ProjectId" class="Project"/>
  </class>

  <class name="Milestone" table="Milestone">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>

    <property name="Name" type="String"/>
    <property name="Description" type="String"/>
    <property name="FinishingDate" type="DateTime"/>
    <property name="CreateDate" type="DateTime"/>
    <property name="ChangeDate" type="DateTime"/>

    <many-to-one name="DataContext" column="DataContextId" class="DataContext"/>
    <many-to-one name="CreatedBy" column="CreatedById" class="User"/>
    <many-to-one name="ChangedBy" column="ChangedById" class="User"/>
    <many-to-one name="Project" column="ProjectId" class="Project"/>
  </class>

  <class name="Ticket" table="Ticket">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>

    <property name="Name" type="String"/>
    <property name="Description" type="String"/>
    <property name="CreateDate" type="DateTime"/>
    <property name="ChangeDate" type="DateTime"/>
    <property name="Type" type="Int32"/>
    <property name="Priority" type="Int32"/>
    <property name="ExpectedEffortHours" type="Int16"/>

    <many-to-one name="CreatedBy" column="CreatedById" class="User"/>
    <many-to-one name="ChangedBy" column="ChangedById" class="User"/>

    <many-to-one name="Category" column="CategoryId" class="Category"/>
    <many-to-one name="Version" column="VersionId" class="Version"/>
    <many-to-one name="AssignedTo" column="AssignedToId" class="User"/>
    <many-to-one name="Project" column="ProjectId" class="Project"/>
    <many-to-one name="Milestone" column="MilestoneId" class="Milestone"/>

    <bag name="Notes" table="Note" lazy="false" cascade="all">
      <key column="TicketId"/>
      <one-to-many class="Note"/>
    </bag>

    <bag name="TimeRecords" table="TimeRecord" lazy="false" cascade="all">
      <key column="TicketId"/>
      <one-to-many class="TimeRecord"/>
    </bag>

    <many-to-one name="State" column="TicketStateId" class="TicketState"/>
  </class>

  <class name="Note" table="Note">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>

    <property name="Message" type="String"/>
    
    <property name="CreateDate" type="DateTime"/>
    <property name="ChangeDate" type="DateTime"/>

    <many-to-one name="Ticket" column="TicketId" class="Ticket"/>
    <many-to-one name="CreatedBy" column="CreatedById" class="User"/>
    <many-to-one name="ChangedBy" column="ChangedById" class="User"/>
  </class>

  <class name="TimeRecord" table="TimeRecord">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>

    <property name="Name" type="String"/>
    <property name="Description" type="String"/>
    <property name="StartDate" type="DateTime"/>
    <property name="EndDate" type="DateTime"/>

    <property name="CreateDate" type="DateTime"/>
    
    <many-to-one name="CreatedBy" column="CreatedById" class="User"/>
    <many-to-one name="Ticket" column="TicketId" class="Ticket"/>
  </class>
  
  <class name="TicketStateMapping" table="TicketStateMapping">
    <id name="Id" column="Id" type="Int64">
      <generator class="identity"/>
    </id>
    <property name="IsAllowed" type="Boolean"/>
    <many-to-one name="State" column="StateId" class="TicketState"/>
    <many-to-one name="MappingState" column="MappingStateId" class="TicketState"/>
  </class>

</hibernate-mapping>